home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / GETUKEY.CMM < prev    next >
Text File  |  1994-03-04  |  2KB  |  43 lines

  1. //************************************************************************
  2. //*** GetUKey.cmm - Cmm source code, used with CEnvi from the command  ***
  3. //*** ver.1         line or from a batch file, to display a prompt and ***
  4. //***               then set the UKEY environment variable to the key  ***
  5. //***               character pressed.                                 ***
  6. //************************************************************************
  7.  
  8. main(argc,argv)
  9. {
  10.    if (argc < 2) {
  11.       // no arguments were given, and so show how to use
  12.       Instructions();
  13.    } else {
  14.       // everything up to the last argument is the prompt
  15.       for ( KeyArg = 1; KeyArg < (argc-1); KeyArg++ )
  16.          printf("%s ",argv[KeyArg])
  17.       KeyList = strupr(argv[KeyArg])
  18.       // flush keyboard
  19.       while kbhit() getch();
  20.       // read until one of the keys from KeyList is pressed
  21.       while ( 0==(key=toupper(getch()))  ||  NULL == strchr(KeyList,key) )
  22.          printf("\a")   // beep because an invalid key was pressed
  23.       printf("%c\n",key)
  24.       // save this key as short environment string UKEY
  25.       (UKEY = "*")[0] = key
  26.    }
  27. }
  28.  
  29. Instructions()
  30. {
  31.    printf("\a\n")
  32.    printf("GetUKey.cmm - Display a prompt and get key from user input.  The\n")
  33.    printf("              environment variable UKEY will be set to the key selected\n")
  34.    printf("\n")
  35.    printf("USAGE: CEnvi GetUKey.cmm [Prompt] <KeyList>\n")
  36.    printf("Where:\n")
  37.    printf("   Prompt  - Text to display before prompting for character\n")
  38.    printf("   KeyList - A string with the characters that will be accepted\n")
  39.    printf("\n")
  40.    printf("Example: CEnvi GetUKey.cmm \"Copy File, Delete it, or Quit? (C/D/Q)\" CDQ\n")
  41. }
  42.  
  43.